#coding=utf-8

import numpy
import re

class Price(object):
    '''每个交易日的价格'''
    def __init__(self, code=None):
        self.code = code
        
        self.date = '1970-01-01'
        
        self.open = 0.0
        self.close = 0.0
        self.highest = 0.0
        self.lowest = 0.0
        
        self.volume = 0
        self.amount = 0
        
        #复权因子
        self.fuquan_ratio = 0

def get_histprices_from_file(code, fn):
    tmp = numpy.fromfile(open(fn, 'rb'), 'i')
    tmp.shape =tmp.size/10, 10
    #return tmp
    
    rs = []
    
    for d in tmp:
    
        p = Price()
        p.code = code
        
        dt = str(d[0])
        p.date = '-'.join([dt[:4], dt[4:6], dt[6:]])
        
        p.open = d[1]/1000.0
        p.highest = d[2]/1000.0
        p.lowest = d[3]/1000.0
        p.close = d[4]/1000.0
        
        p.amount = long(d[5]) * 1000
        p.volume = long(d[6]) * 100
        
        rs.append(p)
        
    return rs

if __name__ == '__main__':
    ps = get_histprices_from_file('600832', './600832.day', )
    for p in ps:
        print p.date, p.open, p.close, p.volume
